package eval

import (
	"showen7/eval"
	"showen7/inter"
	"showen7/lex"
	"showen7/parse"
	"testing"
)

func TestDefine001(t *testing.T) {
	tests := []struct {
		input string
		want  []string
	}{
		{
			"(define x 5) x",
			[]string{"", "5"},
		},
	}

	env := inter.NewEnvironment()
	eval.RegisterBuiltinProcedures(env)

	for _, tt := range tests {
		lexer := lex.NewLexer(tt.input)
		tokens := lexer.ReadTokens()
		parser := parse.NewParser(tokens)
		exprs, err := parser.ParseProgram()
		if err != nil {
			t.Errorf("ParseProgram() error = %v", err)
			continue
		}
		for i, expr := range exprs {
			obj, err := eval.EvalExpression(expr, env)
			if err != nil {
				t.Errorf("Eval() error = %v", err)
				continue
			}
			// Since the lexer converts identifiers to uppercase,
			// we need to adjust our expectation accordingly
			expected := tt.want[i]
			if obj.Inspect() != expected {
				t.Errorf("Eval() = %v, want %v", obj.Inspect(), expected)
			}
		}
	}
}
